package org.hot100_6.leetcode3;

import java.util.HashSet;

public class Solution2 {
    public static void main(String[] args) {
        int maxLength = lengthOfLongestSubstring("aaaa");
        System.out.println(maxLength);
    }
    public static int lengthOfLongestSubstring(String s) {
        int n = s.length();
        HashSet<Character> hashSet = new HashSet<>();

        int left =0;
        int right = 0;
        int maxLength = 0;
        while (right<n){

            while (hashSet.contains(s.charAt(right))){
               hashSet.remove(s.charAt(left));
               left++;
            }
            hashSet.add(s.charAt(right));
            maxLength=Math.max(maxLength,right-left+1);
            right++;
        }

        return maxLength;
    }
}
